use TestHelper;
use EntityBagTestHelper;
use ActionStatusTestHelper;
use ActionResultTestHelper;

sub testInjection{
    my ($obj, $comp, $key) = (shift, shift, shift);

    print "Probando inyeccion de componente\n";

    if($obj->{$key} eq $comp){
	print "    OK\n";
    }else{
	print "--->ERROR: ".$obj."->{".$key."} == ".$obj->{$key}." != ".$comp."\n";
    }
}

sub testPerform{
    my ($action, $expectedResultStatus, $expectedResultMessage) = (shift, shift, shift);

    print "Probando Action->perform()\n";

    my $result = $action->perform();
    testClass($result, "ActionResult");
    checkIs($result->status, $expectedResultStatus);
    testStatusRef($result);
    testMsg($result, $expectedResultMessage);

}

sub testValidate{
    my ($action, $expectedResultStatus, $expectedResultMessage) = (shift, shift, shift);

    print "Probando Action->__validate()\n";

    my $result = $action->__validate();
    testClass($result, "ActionResult");
    checkIs($result->status, $expectedResultStatus);
    testStatusRef($result);
    testMsg($result, $expectedResultMessage);

}

sub testParamIdentity{
    my ($action, $params) = (shift, shift);
    
    print "Probando identidad de los parametros\n";

    if($action->params eq $params){
	print "    OK\n";
    }else{
	print "--->ERROR: ".$action->params." ne ".$params."\n";
    }
}

sub testActionParameters{
    my $action = shift;
    my $parameterNames = shift;
    my $parameterValues = shift;

    my $error = 0;

    print "Probando parametros\n";

    for(my $i = 0; $i< (scalar(@{$parameterNames})); $i++){
	my $param = $parameterNames->[$i];
	my $val = $parameterValues->[$i];

	my $fromAction = $action->params->{$param};
	
#	print $fromAction."=".$val." for param ".$param."\n";
	if($fromAction ne ("".$val)) {
	    print "--->ERROR: action->params(".$param.") = ".$fromAction." != ".$val."\n";
	    $error = 1;
	}
    } # foreach parameter name

    print "    OK\n" unless($error);
}

1;
